package com.coocaa.ops.api.v1.home.biz;

import com.coocaa.ops.api.common.validator.PolicyValidator;
import com.coocaa.ops.api.v1.home.mapper.IHomepageMapper;
import com.coocaa.ops.api.v1.home.model.internal.ModuleWithDmpInfoModel;
import com.coocaa.ops.api.v1.home.model.query.HomeQueryModel;
import com.coocaa.ops.common.core.biz.homepage.entity.HomeModuleContentConfigInfo;
import com.coocaa.ops.common.core.biz.homepage.entity.HomepageInfoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tangminghong
 * @date 2020-06-22
 */
@Service
public class HomepageBizImpl implements IHomepageBiz {

    @Autowired
    private IHomepageMapper homepageMapper;

    @Override
    public HomepageInfoEntity getHomepageAndModuleList(HomeQueryModel homeQueryModel) {
        if (PolicyValidator.isFormalPolicy(homeQueryModel.getPolicyCategory())) {
            return homepageMapper.selectHomepageModuleList(homeQueryModel.getHomepageId());
        } else {
            return homepageMapper.selectHomepageModuleListForTestPolicy(homeQueryModel.getHomepageId());
        }
    }

    @Override
    public List<HomeModuleContentConfigInfo> getDmpModuleList(HomeQueryModel homeQueryModel) {
        if (PolicyValidator.isFormalPolicy(homeQueryModel.getPolicyCategory())) {
            return homepageMapper.selectDmpModules(homeQueryModel.getHomepageId());
        } else {
            return homepageMapper.selectDmpModulesForTestPolicy(homeQueryModel.getHomepageId());
        }
    }
}
